@extends('admin.layout.layout', ['row' => @$page])
@section('style')
    <style>
        .table .tth{
            background-color: rgba(0, 0, 0, 0.05);
            width: 150px;
            font-weight: bold;
        }
        .table .ttd{
            width: 350px;
        }
        .table .ttt{
            padding: 0;
        }
        .ttt .table{
            margin: 0;
        }
        .ttt .table img + p{
            text-align: center;
            margin: 10px 0 0;
        }
        .tst{
            color: #00b050;
            font-weight: 700;
            text-align: center;
            font-size: 1.25rem;
        }
    </style>
@endsection
@section('contain')


    <div class="portlet">
        <div class="portlet-title">
            <div class="caption">
                <x-portlet-breadcrumb :page="$page"></x-portlet-breadcrumb>
            </div>
            <div class="actions">
                {{--<div class="item">
                    <a href="/{{ request()->path() }}/create" class="btn btn-sm btn-primary">{{ ts('addnew') }}</a>
                </div>--}}
            </div>
        </div>

        <div>
            <table class="table s3">
                <tbody>
                <tr>
                    <td class="tth">{{ ts('warrantyid') }}</td>
                    <td class="ttd" colspan="5">{{ $data->warranty_id }}</td>
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('CUSTOMER') }}</td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('CUSTOMERNAME') }}</td>
                    <td class="ttd">{{ $data->first_name }}</td>
                    <td class="tth">{{ ts('phonenumber') }}</td>
                    <td class="ttd">{{ $data->extension }} {{ $data->phone_number }}</td>
                    <td class="tth">{{ ts('email') }}</td>
                    <td class="ttd">{{ $data->email_address }}</td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('region') }}</td>
                    <td>{{ ts('region_master.'.$data->region_id) }}</td>
                    <td class="tth">{{ ts('province') }}</td>
                    <td>{{ ts('province_master.'.$data->province_id) }}</td>
                    <td class="tth">{{ ts('city') }}</td>
                    <td>{{ ts('cities.'.$data->city) }}</td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('addresss') }}</td>
                    <td colspan="3">{{ $data->address }}</td>
                    <td class="tth">{{ ts('zip') }}</td>
                    <td>{{ $data->zip }}</td>
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('VEHICLEINFORMATION') }}</td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('year') }}</td>
                    <td>{{ $data->year_id }}</td>
                    <td class="tth">{{ ts('make') }}</td>
                    <td>{{ ts('make_master.'.$data->make_id) }}</td>
                    <td class="tth">{{ ts('model') }}</td>
                    <td>
                        {{ ts('model_master.'.$data->model_id) ?: $data->model_id }}
                    </td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('licenseplate') }}</td>
                    <td>{{ $data->license_plate }}</td>
                    <td class="tth">{{ ts('vinnumber') }}</td>
                    <td colspan="3">{{ $data->vin_number }}</td>
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('INSTALLATIONINFORMATION') }}</td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('qudao') }}</td>
                    <td colspan="5">{{ getJc($data->user_id) }}</td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('INSTALLERNAME') }}</td>
                    <td>{{ $data->installer_name }}</td>
                    <td class="tth">{{ ts('INSTALLATIONDATE') }}</td>
                    <td>{{ fdate($data->installation_date) }}</td>
                    <td class="tth">{{ ts('INSTALLERPRICE') }}</td>
                    <td>{{ $data->installation_price }}</td>
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('INSTALLATIONPICTURE') }}</td>
                </tr>
                <tr>
                    <td colspan="6" class="ttt p-3">
                        <x-warranty-image :warranty="$data"></x-warranty-image>
                    </td>
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('VEHICLECOVERAGE') }}</td>
                </tr>
                <tr>
                    <td colspan="6" class="ttt">
                        <table class="table text-center">
                            <thead>
                            <tr>
                                <th>{{ ts('PART') }}</th>
                                <th>{{ ts('ROLLNUMBER') }}</th>
                                <th>{{ ts('LENGTH') }}</th>
                                <th>{{ ts('FILMTYPE') }}</th>
                                <th>{{ ts('FILMWIDTH') }}</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($data->warranty_to_vehicle_coverage as $v)
                                <tr>
                                    <td>{{ ts('part_master.'.$v->part_id) }}</td>
                                    <td>{{ $v->roll_number }}</td>
                                    <td>{{ $v->length }} cm</td>
                                    <td>{{ ts('film_type_master.'.$v->film_type_id) }}</td>
                                    <td>{{ $v->width }}</td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('BCSM') }}</td>
                </tr>
                <tr>
                    <td colspan="6" height="64">{{ $data->additional_comments }}</td>
                </tr>
                </tbody>
            </table>

        </div>
        @if($verify->approved == 0)
            <div class="my-3">
                <button class="btn btn-primary mr-5" onclick="verifyWarranty(1)">{{ ts('TY') }}</button>
                <button class="btn btn-danger ml-5" onclick="verifyWarranty(2)">{{ ts('JJ') }}</button>
            </div>
        @else
            <div class="my-3 alert alert-info">
                <p>{{ ts('fqr') }}：{{ getJc($verify->created_by) }}</p>
                <p>{{ ts('fqsj') }}：{{ fdate2($verify->created_at) }}</p>
                <p>{{ ts('status') }}：{{ ts('STA'.$verify->approved) }}</p>
                <p>{{ ts('EFFECTIVEDATE') }}：{{ fdate2($verify->updated_at) }}</p>
                <p>{{ ts('APPROVEDBYUSER') }}：{{ $verify->admin_name ?: getJc($verify->updated_by) }}</p>
                <p>{{ ts('explain') }}：{{ $verify->note }}</p>
            </div>
        @endif
        <h3 class="section_sub_title">{{ ts('LSJL') }}</h3>
        <table class="table" data-toggle="table">
            <thead>
            <tr>
                <th>{{ ts('fqr') }}</th>
                <th>{{ ts('fqsj') }}</th>
                <th>{{ ts('APPROVEDBYUSER') }}</th>
                <th>{{ ts('CZ') }}</th>
                <th>{{ ts('CZSJ') }}</th>
                <th>{{ ts('explain') }}</th>
            </tr>
            </thead>
            <tbody>
            @foreach(@$records ?: [] as $v)
                <tr>
                    <td>{{ @$v->fqr }}</td>
                    <td>{{ fdate2(@$v->created_at) }}</td>
                    <td>{{ @$v->admin_name ?: @$v->czy }}</td>
                    <td>{{ ts('STA'.$v->approved) }}</td>
                    <td>{{ fdate2(@$v->updated_at) }}</td>
                    <td>{{ @$v->note }}</td>
                </tr>
            @endforeach
            </tbody>
        </table>

    </div>


@endsection


@section('script')
    <script>
        function verifyWarranty(verify) {
            var url = '/{{ request()->path() }}/verify';
            var msg;
            if (verify == 1) {
                msg = '确认通过该质保信息？';
            }  else {
                msg = '确认拒绝该质保信息？';
            }
            mySwalV2({t:msg, c:'input'}).then(function (d) {
                request.post(url, {
                    verify: verify,
                    note: d
                }).then(function (d) {
                    mySwal2()
                }).catch(function (d) {
                    sw3(d.msg, 'error')
                })
            }).catch(function (d) {
                console.log(d)
            })

            console.log(verify)
        }
    </script>
@endsection